Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add priorityClassName in PropagationPolicy & ClusterPropagationPolicy #5962

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

seanlaii
Copy link
Contributor

@seanlaii seanlaii commented Dec 19, 2024

What type of PR is this?
/kind api-change
/kind feature

What this PR does / why we need it:
Add SchedulePriority to PropagationPolicy & ClusterPropagationPolicy to support flexible priority class resolution strategies:

  • KubePriorityClass: Use Kubernetes native PriorityClass
  • PodPriorityClass: Use priority from workload's PodTemplate
  • FederatedPriorityClass: Reserved for future Karmada-specific priority classes

This enhancement allows users to:

  1. Specify which priority class source to use
  2. Control resource scheduling priority
  3. Maintain consistent priority behavior with Kubernetes

Which issue(s) this PR fixes:
Part of #5961

Special notes for your reviewer:

  • Default source is KubePriorityClass
  • Falls back to global default if unspecified
  • FederatedPriorityClass is reserved for future implementation
  • All new fields are optional to maintain backward compatibility

Does this PR introduce a user-facing change?:

Add SchedulePriority field to PropagationPolicy and ClusterPropagationPolicy:
- Supports multiple priority class sources (Kubernetes, PodTemplate, Federated[future])
- Configurable priority class resolution strategy
- Maintains compatibility with Kubernetes priority behavior
- Optional fields preserve backward compatibility

@karmada-bot karmada-bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Dec 19, 2024
@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Dec 19, 2024
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 19, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 19, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.10%. Comparing base (f555413) to head (4bf165a).
Report is 4 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5962      +/-   ##
==========================================
- Coverage   48.12%   48.10%   -0.02%     
==========================================
  Files         668      668              
  Lines       55291    55291              
==========================================
- Hits        26607    26599       -8     
- Misses      26949    26956       +7     
- Partials     1735     1736       +1     
Flag Coverage Δ
unittests 48.10% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 19, 2025
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/assign
Start working on it!

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whitewindmills Would you like to take another look?

Comment on lines 204 to 219
// SchedulePriority defines how Karmada should resolve the priority and preemption policy
// for workload scheduling.
//
// Valid options for PriorityClassSource are:
// - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1)
// - PodPriorityClass: Uses PriorityClassName from PodTemplate (PodSpec.PriorityClassName)
// - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented)
//
// PriorityClassName behavior:
//
// For KubePriorityClass:
// - If specified: Uses the named Kubernetes PriorityClass
// - If empty: Uses cluster's global default PriorityClass
// - If neither exists: Sets priority=0 and preemptionPolicy=Never
//
// For PodPriorityClass:
// - Uses PriorityClassName from PodTemplate
// - Falls back to global default if not found
// - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never
//
// For FederatedPriorityClass:
// - Reserved for future use
// - Current behavior undefined
//
// +optional
SchedulePriority *SchedulePriority `json:"schedulePriority,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't have to explain the valid options outside, because they are described inside of SchedulePriority. But we can give some overall descriptions, like:

Suggested change
// SchedulePriority defines how Karmada should resolve the priority and preemption policy
// for workload scheduling.
//
// Valid options for PriorityClassSource are:
// - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1)
// - PodPriorityClass: Uses PriorityClassName from PodTemplate (PodSpec.PriorityClassName)
// - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented)
//
// PriorityClassName behavior:
//
// For KubePriorityClass:
// - If specified: Uses the named Kubernetes PriorityClass
// - If empty: Uses cluster's global default PriorityClass
// - If neither exists: Sets priority=0 and preemptionPolicy=Never
//
// For PodPriorityClass:
// - Uses PriorityClassName from PodTemplate
// - Falls back to global default if not found
// - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never
//
// For FederatedPriorityClass:
// - Reserved for future use
// - Current behavior undefined
//
// +optional
SchedulePriority *SchedulePriority `json:"schedulePriority,omitempty"`
// SchedulePriority defines how Karmada should resolve the priority and preemption policy
// for workload scheduling.
//
// This setting is particularly useful for controlling the scheduling behavior of offline workloads.
// By setting a higher or lower priority, users can control which workloads are scheduled first.
// Additionally, it also allows to specify the preempt policy that higher-priority workloads can
// preempt lower-priority ones in scenarios where resource contention occurs.
//
// Note: This feature is currently in the alpha stage. The priority-based scheduling functionality is
// controlled by the PriorityBasedScheduling feature gate, and preemption is controlled by the
// PriorityBasedPreemptiveScheduling feature gate. At this time, only priority-based scheduling is
// supported, while preemption functionality is not yet available and will be introduced in the future
// releases as the feature matures.
//
// +optional
SchedulePriority *SchedulePriority `json:"schedulePriority,omitempty"`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.

Comment on lines 695 to 691
// - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1)
// - PodPriorityClass: Uses PriorityClassName from PodTemplate (PodSpec.PriorityClassName)
// - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented)
//
// +kubebuilder:default="KubePriorityClass"
// +kubebuilder:validation:Enum=FederatedPriorityClass;KubePriorityClass;PodPriorityClass
// +optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we provide support for KubePriorityClass only, right?

Shall we add a comment to PodPriorityClass to explain a little bit, something like not yet implemented?

In addition, please shorten the +kubebuilder:validation:Enum with supported options.

// - Reserved for future use
// - Current behavior undefined
//
// +optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// +optional
// +required

Can we restrict this as a required in the current version, just hope to work out a simple version quickly.

@seanlaii In your use cases, will you set a specific PriorityClassName for each workload, or will you rely on the default one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we currently set a default priority class for every workload if no priority class is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we currently set a default priority class for every workload if no priority class is set.

+1
I think that making the configuration clearer, and also a relief for the implementation.

@whitewindmills
Copy link
Member

/assign

//
// For PodPriorityClass:
// - Uses PriorityClassName from PodTemplate
// - Falls back to global default if not found
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid people don't know what the global default is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the description to

// If the specified PriorityClass is not found, falls back to the cluster's default PriorityClass
//   (i.e., the PriorityClass marked as the global default in the cluster).

WDYT?

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

I'm going to move this forward to avoid blocking the other tasks.
And I'll double check the comments before releasing, ensuring the comments consist with the minimal version.

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 18, 2025
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 18, 2025
@karmada-bot karmada-bot merged commit 9f8d71e into karmada-io:master Feb 18, 2025
21 checks passed
@seanlaii seanlaii deleted the priorityclass branch February 18, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants